package juego

import org.uqbar.arena.windows.SimpleWindow
import model.AppModel.ViajarAppModel
import org.uqbar.arena.windows.WindowOwner
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.layout.VerticalLayout
import org.uqbar.arena.widgets.List
import org.uqbar.arena.bindings.PropertyAdapter
import unq.model.Pais
import org.uqbar.arena.widgets.Button
import model.AppModel.ResolverMisterioAppModel
import org.uqbar.commons.utils.Observable

@Observable
class ViajarWindow extends SimpleWindow<ViajarAppModel> {

	new(WindowOwner parent, ViajarAppModel model) {
		super(parent, model)
		title = "Viajar"

	}

	override protected addActions(Panel actionsPanel) {

		new Button(actionsPanel) => [
			caption = "Volver al Pais Anterior"
			onClick = [|
				new ResolviendoMisterioWindow(this, new ResolverMisterioAppModel(this.modelObject.caso, this.modelObject.anterior)).open
				close
			]
		]
		new Button(actionsPanel) => [
			caption = "viajar"
			onClick = [ |
				modelObject.destinoFallido()
				new ResolviendoMisterioWindow(this, new ResolverMisterioAppModel(this.modelObject.caso, this.modelObject.seleccionado)).open
				close
			]
		]
	}

	override protected createFormPanel(Panel mainPanel) {
		new Panel(mainPanel) => [
			setLayout(new VerticalLayout())
			new Label(it) => [text = "Estas en:" + modelObject.caso.paisActual.nombre fontSize = 13]
			new List(mainPanel) => [
				val binding = bindItemsToProperty("caso.paisActual.conexiones")
				binding.setAdapter(new PropertyAdapter(Pais, "nombre"))
				bindValueToProperty("seleccionado")
				width = 200
				heigth = 50
			]
		]
	}

}
